package com.servlet;

import com.dao.imp.FindGoodsDaoImp;
import com.entity.Good;
import com.util.DBConn;
import net.sf.json.JSONArray;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/11/24 19:39
 **/

@WebServlet(name = "GetGoodsByParentIdServlet", value = "/GetGoodsByParentIdServlet")
public class GetGoodsByParentIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String parentId = request.getParameter("parentId");
        FindGoodsDaoImp findGoodsDaoImp = new FindGoodsDaoImp();
        List goods = findGoodsDaoImp.findGoodsByParentTypeIsUpload(parentId);

//        DBConn.closeConn();

//        System.out.println(goods.get(1));
        JSONArray json = JSONArray.fromObject(goods);
        response.getWriter().print(json);
    }
}
